#!/usr/bin/env bash

# Copyright 2017 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

ZIRCON_PARTITION="boot,misc,recovery,tee"
FLASH_PART=a
BOOT_PART=a

CMDLINE=

function HELP {
    echo "help:"
    echo "-c <cmd line>     : Extra command line options"
    echo "-m                : Add mexec option to command line"
    echo "-B <partition>    : Partition to boot from (a, b, r) (x to skip)"
    echo "-P <partition>    : Partition flash (a, b, r) (x to skip)(A for all)"
    echo "-h for help"
    exit 1
}

while getopts "c:mB:P:" FLAG; do
    case $FLAG in
        c) CMDLINE+="-c ${OPTARG}";;
        m) CMDLINE+="-m";;
        B) BOOT_PART="${OPTARG}";;
        P) FLASH_PART="${OPTARG}";;
        h) HELP;;
        \?)
            echo unrecognized option
            HELP
            ;;
    esac
done
shift $((OPTIND-1))




    exec $DIR/fastboot-flash -b vim2 -P ${FLASH_PART} -B ${BOOT_PART} ${CMDLINE} -Z ${ZIRCON_PARTITION} "$@"


